package com.boesch.electroOffice.dataaccess.mapper;

import java.io.Serializable;
import java.sql.ResultSet;
import java.sql.SQLException;

import org.springframework.jdbc.core.RowMapper;

import com.boesch.electroOffice.model.electroOffice.Identifier;
import com.boesch.electroOffice.utils.DateUtils;

/**
/* This class mappes the rows from database to a Identifier object.
 * 
 * @author Ralph Koster
 *
 */
public class IdentifierMapper implements RowMapper<Identifier>, Serializable {

	private static final long serialVersionUID = -1313666974075648831L;

	/**
	 * Mapps all rows from database to a Identifier object.
	 * 
	 * @see org.springframework.jdbc.core.RowMapper
	 */
	public Identifier mapRow(ResultSet rs, int rowNum) throws SQLException {
		Identifier identifier = new Identifier();

		identifier.setId(rs.getInt("Id_pk"));
		identifier.setEntity(rs.getString("Entity"));
		identifier.setSubentity(rs.getString("Subentity"));
		identifier.setIdentifier(rs.getString("Identifier"));
		identifier.setName(rs.getString("Name"));
		identifier.setShortname(rs.getString("Shortname"));
		identifier.setDescription(rs.getString("Description"));
		identifier.setSortorder(rs.getInt("Sortorder"));
		identifier.setCreatedBy(rs.getString("Createdby"));
		identifier.setCreatedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Createdat")));
		identifier.setModifiedBy(rs.getString("Modifiedby"));
		identifier.setModifiedAt(DateUtils.convertTimestampToLocalDateTime(rs.getTimestamp("Modifiedat")));
		identifier.setVersion(rs.getInt("Version"));

		return identifier;
	}
}
